<template>
    <div style="height: 100%; width: 100%; position: relative">
        <div :class="!is_showselother ? 'pagetop' : 'pagetopother'">
            <div style="width: 100%; overflow: auto">
                <div style="float: left; width: 100%">
                    <table style="font-size: 12px; width: 90%" class="table1style" border="0">
                        <col style="width: 5%" />
                        <col style="width: 10%" />
                        <col style="width: 1%" />
                        <col style="width: 10%" />
                        <col style="width: 4%" />
                        <col style="width: 10%" />
                        <col style="width: 5%" />
                        <col style="width: 10%" />
                        <col style="width: 5%" />
                        <col style="width: 10%" />
                        <col style="width: 5%" />
                        <col style="width: 10%" />
                        <col style="width: 5%" />
                        <col style="width: 10%" />
                        <col style="width: 11%" />
                        <tr>
                            <td align="right">创建日期</td>
                            <td>
                                <el-date-picker v-model="searchObj.txtdatetime1" type="date" value-format="yyyy-MM-dd"
                                    size="mini" placeholder="开始日期" :clearable="false" style="width: 100%"></el-date-picker>
                            </td>
                            <td>至</td>
                            <td>
                                <el-date-picker v-model="searchObj.txtdatetime2" type="date" value-format="yyyy-MM-dd"
                                    size="mini" placeholder="结束日期" :clearable="false" style="width: 100%"></el-date-picker>
                            </td>
                            <td align="right">条码号</td>
                            <td>
                                <el-input v-model="searchObj.txtbarcode" size="mini" clearable></el-input>
                            </td>
                            <td align="right">申请科室</td>
                            <td>
                                <rm-ddl-common datatype="dept" dataname="科室" v-model="searchObj.txtreqdeptno" size="mini"
                                    width="100%" @change="deptChange"></rm-ddl-common>
                            </td>
                            <td align="right">送检医院</td>
                            <td>
                                <rm-ddl-common datatype="hospital" dataname="医院" v-model="searchObj.txthospcode" size="mini"
                                    width="100%" @change="hospitalChange"></rm-ddl-common>
                            </td>
                            <td></td>
                            <td align="left">
                                <span :underline="false" @click="btn_showselother">{{ is_showselother ? "收起其它条件" : "展开其它条件"
                                }}<i :class="is_showselother ? 'el-icon-caret-top' : 'el-icon-caret-bottom'"></i></span>
                            </td>
                        </tr>
                        <tr v-if="is_showselother">
                            <td align="right">申请项目</td>
                            <td colspan="3">
                                <rm-ddl-common datatype="reqitem" dataname="申请项目" v-model="searchObj.txtreqitem" size="mini"
                                    width="100%" :readonly="true" :clearable="true" @change="reqitemChange"></rm-ddl-common>
                            </td>
                            <td align="right">病历号</td>
                            <td>
                                <el-input v-model="searchObj.txtpatno" size="mini" style="width: 100%" clearable></el-input>
                            </td>
                            <td align="right">病人姓名</td>
                            <td>
                                <el-input v-model="searchObj.txtpatname" size="mini" style="width: 100%"
                                    clearable></el-input>
                            </td>
                            <td align="right">身份证号</td>
                            <td>
                                <el-input v-model="searchObj.txtpatidcard" size="mini" style="width: 100%"
                                    clearable></el-input>
                            </td>
                            <td align="right">病人类型</td>
                            <td>
                                <rm-ddl-common datatype="seccode" kindno="PT" dataname="病用户类型"
                                    v-model="searchObj.txtpattype" width="100%" @change="PTChange"></rm-ddl-common>
                            </td>
                            <td align="right">创建用户</td>
                            <td>
                                <rm-ddl-common datatype="userinfo" dataname="用户" v-model="searchObj.txtcreateuser"
                                    width="100%" @change="userinfoChange"></rm-ddl-common>
                            </td>
                        </tr>
                    </table>
                </div>
                <div style="width: 100%; text-align: right">
                    <table style="width: 100%">
                        <tr>
                            <td>
                                <el-button icon="el-icon-search" @click="queryData" type="primary"
                                    :disabled="changeflag">查询</el-button>
                                <el-button icon="el-icon-check" @click="btnApprove()"
                                    :disabled="changeflag">审核(F6)</el-button>
                                <el-button icon="el-icon-upload2" @click="exportExcel">导出</el-button>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
        <div :class="!is_showselother ? 'pagecenter' : 'pagecenterother'">
            <div class="middle-center table-bottom-content">
                <vxe-table :data.sync="master" :loading="loading" :select-config="{ reserve: true }"
                    :sort-config="{ trigger: 'cell', checkAll: true, reserve: true }" @current-change="currentChangeEvent"
                    border show-header-overflow :height="!is_showselother ? 'auto' : '100%'" highlight-current-row
                    highlight-hover-column :row-class-name="RowClassName" ref="lxTableTemp" resizable show-overflow @cell-dblclick="dblclickTemp" size="mini" stripe>
                    <vxe-table-column type="selection" width="45" header-align="center" align="center"></vxe-table-column>
                    <vxe-table-column field="isPhoto" title="图片" width="35" align="center" header-align="center">
                        <template v-slot="{ row }">
                            <div v-show = "row.isPhoto != '0'">
                                {{ row.isPhoto }}<i class="el-icon-picture" style="padding: 2px !important"></i>
                            </div>
                        </template>
                    </vxe-table-column>
                    <vxe-table-column field="hospname" title="送检医院" width="123" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_typename" title="来源" width="50" header-align="center"></vxe-table-column>
                    <vxe-table-column field="create_dt" title="登记时间" width="130" header-align="center"
                        :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                    <vxe-table-column field="pat_name" title="姓名" width="66" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_no" title="病历号" width="90" header-align="center"></vxe-table-column>
                    <vxe-table-column field="req_groupna" title="分单类别" width="88" header-align="center"> </vxe-table-column>
                    <vxe-table-column field="barcode" title="条码号" width="117" header-align="center"></vxe-table-column>
                    <vxe-table-column field="emer_flag" title="加急" width="50" header-align="center">
                        <template v-slot="{ row }">
                            <span style="color: red">{{ row.emer_flag == "1" ? "急" : "" }}</span>
                        </template>
                    </vxe-table-column>
                    <vxe-table-column field="sample_items" title="申请项目(简称，部分)" width="203"
                        header-align="center"></vxe-table-column>
                    <vxe-table-column field="req_deptname" title="申请科室" width="94" header-align="center"></vxe-table-column>
                    <vxe-table-column field="req_docname" title="申请医生" width="80" header-align="center"></vxe-table-column>
                    <vxe-table-column field="req_bedno" title="床号" width="74" header-align="center"></vxe-table-column>
                    <vxe-table-column field="specimen_name" title="标本类型" width="80"
                        header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_sexname" title="性别" width="50" header-align="center"
                        align="center"></vxe-table-column>
                    <vxe-table-column field="pat_agestr" title="年龄" width="50" header-align="center"></vxe-table-column>
                    <vxe-table-column field="create_username" title="创建用户" width="80"
                        header-align="center"></vxe-table-column>
                    <vxe-table-column field="sampled_dt" title="采样时间 " width="130" header-align="center"
                        :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                    <vxe-table-column field="sampled_username" title="采样用户" width="80"
                        header-align="center"></vxe-table-column>
                    <vxe-table-column field="req_dt" title="申请日期 " width="130" header-align="center"
                        :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                    <vxe-table-column field="pat_diag" title="临床诊断 " width="110" header-align="center"></vxe-table-column>
                    <vxe-table-column field="amount" title="应收金额 " width="80" header-align="center"
                        align="right"></vxe-table-column>
                    <vxe-table-column field="charge_flag" title="计价标志 " width="73" header-align="center"></vxe-table-column>
                    <vxe-table-column field="saleman" title="销售员 " width="80" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_cardno" title="就诊卡号 " width="100" header-align="center"></vxe-table-column>
                    <vxe-table-column field="req_comm" title="医生备注 " width="127" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_idcardno" title="身份证号 " width="150"
                        header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_birth" title="生日 " width="90" header-align="center"
                        :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                    <vxe-table-column field="pat_address" title="地址" width="155" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_phone" title="联系电话" width="124" header-align="center"></vxe-table-column>
                    <vxe-table-column field="req_wardname" title="所属病区 " width="105"
                        header-align="center"></vxe-table-column>
                    <vxe-table-column field="specimen_code" title="标本类型代码 " width="100"
                        header-align="center"></vxe-table-column>
                    <vxe-table-column field="req_groupid" title="分单类别ID" width="80"
                        header-align="center"></vxe-table-column>
                    <template v-slot:fix>
                        <div
                            style="font-size: 17px; padding-top: 3px; background-color: #fff; text-align: center; font-weight: bold">
                            <span style="color: red; margin-left: 10px">数量: {{ datacnt }}</span><span
                                style="color: blue; margin-left: 35px">金额: ￥{{ amountsum }}</span>
                        </div>
                    </template>
                </vxe-table>
            </div>
            <div class="middle-right">
                <div v-if="!haveUpt" class="show-area"></div>
                <rm-layout-top splitcolor="white" :splitwidth="5" :fixsize="formheight" :key="formkey">
                    <template v-slot:fix>
                        <div style="border: 1px solid #ccc; overflow: auto" class="myclass">
                            <el-form ref="masterListForm" :model="masterList" :disabled="nodata" size="mini"
                                class="table2style">
                                <table style="width: 100%; font-size: 12px; font-weight: 500">
                                    <tr v-for="(list, index) in columnData" :key="index">
                                        <td v-for="(item, sindex) in list" :key="sindex">
                                            <table style="width: 100%; border-spacing: 0.5px" border="0">
                                                <tr>
                                                    <td style="width: 70px" align="right"
                                                        :class="item.notnull == '1' ? 'must-param' : ''">{{ item.col_label
                                                        }}</td>
                                                    <td style="width: 140px" v-if="item.valuetype == '2'">
                                                        <div v-if="forminfo.hasOwnProperty(item.col_code)">
                                                            <el-input
                                                                v-model="masterList[forminfo[item.col_code].field.split('$')[1]]"
                                                                style="width: 100%" :ref="'input' + item.seqflag"
                                                                @keyup.enter.native="nextFocus(item.col_code, item.seqflag)"
                                                                @input="hasChange" @dblclick.native="opendialog(item)"
                                                                @keyup.space.native="SpaceEvent(item)"
                                                                @keyup.up.native="InputMove('up', item.col_code, item.seqflag)"
                                                                @keyup.down.native="InputMove('dn', item.col_code, item.seqflag)"
                                                                @focus="InputFocus(item.col_code, item.seqflag)"
                                                                @change="inputChangeEvent($event, item.col_code, item.seqflag)"
                                                                :id="item.col_code"></el-input><!-- :disabled="item.enabled=='1'"-->
                                                        </div>
                                                        <div v-else>
                                                            <el-input v-model="masterList[item.col_code]"
                                                                style="width: 100%" :ref="'input' + item.seqflag"
                                                                @keyup.enter.native="nextFocus(item.col_code, item.seqflag)"
                                                                @input="hasChange" @dblclick.native="opendialog(item)"
                                                                @keyup.space.native="opendialog(item)"
                                                                @keyup.up.native="InputMove('up', item.col_code, item.seqflag)"
                                                                @keyup.down.native="InputMove('dn', item.col_code, item.seqflag)"
                                                                @focus="InputFocus(item.col_code, item.seqflag)"
                                                                @change="inputChangeEvent($event, item.col_code, item.seqflag)"
                                                                :id="item.col_code"></el-input><!-- :disabled="item.enabled=='1'"-->
                                                        </div>
                                                    </td>
                                                    <td style="width: 130px" v-else-if="item.valuetype == '7'">
                                                        <el-date-picker v-model="masterList[item.col_code]"
                                                            :inputable="true" :ref="'input' + item.seqflag"
                                                            :clearable="false" type="date" placeholder="选择日期"
                                                            value-format="yyyy-MM-dd" style="width: 100%"
                                                            @keyup.enter.native="nextFocus(item.col_code, item.seqflag)"
                                                            @input="inputChangeEvent($event, item.col_code, item.seqflag)"
                                                            @dblclick.native="opendialog(item)"
                                                            @keyup.up.native="InputMove('up', item.seqflag)"
                                                            @keyup.down.native="InputMove('dn', item.seqflag)"
                                                            @focus="InputFocus(item.col_code, item.seqflag)"
                                                            :id="item.col_code" v-if="item.col_code == 'pat_birth'"
                                                            @change="inputChangeEvent($event, item.col_code, item.seqflag)">
                                                        </el-date-picker>
                                                        <el-date-picker v-model="masterList[item.col_code]"
                                                            :inputable="true" :ref="'input' + item.seqflag"
                                                            :clearable="false" type="datetime" placeholder="选择日期"
                                                            value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%"
                                                            @keyup.enter.native="nextFocus(item.col_code, item.seqflag)"
                                                            @input="hasChange" @dblclick.native="opendialog(item)"
                                                            @keyup.up.native="InputMove('up', item.seqflag)"
                                                            @keyup.down.native="InputMove('dn', item.seqflag)"
                                                            @focus="InputFocus(item.col_code, item.seqflag)"
                                                            :id="item.col_code" v-else> </el-date-picker>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr v-for="(list, index) in columnDataDisabled" :key="index * 100 + 100">
                                        <td v-for="(item, sindex) in list" :key="sindex * 1000 + 1000">
                                            <table style="width: 100%; border-spacing: 0.5px" border="0">
                                                <tr>
                                                    <td style="width: 70px" align="right">{{ item.col_label }}</td>
                                                    <td style="width: 140px" v-if="item.valuetype == '2'">
                                                        <el-input v-model="masterList[item.col_code]" style="width: 100%"
                                                            :disabled="item.enabled == '0'" @change="hasChange"></el-input>
                                                    </td>
                                                    <td style="width: 130px" v-else-if="item.valuetype == '7'">
                                                        <el-date-picker v-model="masterList[item.col_code]"
                                                            :clearable="false" type="date" placeholder="选择日期"
                                                            value-format="yyyy-MM-dd" style="width: 100%"
                                                            :disabled="item.enabled == '0'" @change="hasChange">
                                                        </el-date-picker>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr v-for="(list, index) in columnDataChk" :key="index * 10000 + 10000">
                                        <td v-for="(item, sindex) in list" :key="sindex * 100000 + 100000">
                                            <table style="width: 100%; border-spacing: 0.5px" border="0">
                                                <tr>
                                                    <td style="width: 70px" align="right"
                                                        :class="item.notnull == '1' ? 'must-param' : ''">{{ item.col_label
                                                        }}</td>
                                                    <td style="width: 130px">
                                                        <el-checkbox v-model="masterList[item.col_code]" true-label="1"
                                                            false-label="0" @change="hasChange"></el-checkbox>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </el-form>
                        </div>
                    </template>
                    <div style="height: 100%; width: 100%">
                        <div class="table-bottom-content" style="height: 100%">
                            <vxe-table :data.sync="detail" :loading="right_loading" :select-config="{ reserve: true }"
                                :sort-config="{ trigger: 'cell' }" border :height="!is_showselother ? 'auto' : '100%'"
                                highlight-current-row highlight-hover-column ref="rxTable" resizable show-overflow
                                size="mini" stripe
                                :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: true, activeMethod: activeMethod }">
                                <vxe-table-column field="seq" title="序号 " width="40"
                                    header-align="center"></vxe-table-column>
                                <vxe-table-column field="req_itemcode" title="项目名称" width="166" header-align="center"
                                    :edit-render="{ name: 'input' }">
                                    <template v-slot:edit="{ row }">
                                        <rm-selecttable ref="tablereqselect" :currentLable="row.req_itemname"
                                            :showName="showName" :tableColumnData="allReqsheetTable"
                                            :ftableDataList="fallReqsheetList" :filterColumn="filterColumn"
                                            @change="changeReqitem($event, row)"
                                            :popperappendtobody="false"></rm-selecttable>
                                    </template>
                                    <template v-slot="{ row }">
                                        <span>{{ getShowName(row.req_itemcode, "allReqsheetList") }}</span>
                                    </template>
                                </vxe-table-column>
                                <vxe-table-column field="item_price" title="价格" width="40" header-align="center"
                                    align="right"></vxe-table-column>
                                <vxe-table-column field="specimen_code" title="标本类型" width="88" header-align="center">
                                    <template v-slot="{ row }">
                                        <rm-ddl-common :disabled=true datatype="specimen" dataname="标本类型"
                                            v-model="row.specimen_code" width="100%" key="specimen_code"></rm-ddl-common>
                                    </template>
                                </vxe-table-column>
                                <vxe-table-column field="qty" title="数量" width="40" header-align="center"
                                    align="center"></vxe-table-column>
                                <vxe-table-column field="amount" title="金额" width="40" header-align="center"
                                    align="right"></vxe-table-column>
                                <vxe-table-column field="req_groupname" title="分单类别" width="80"
                                    header-align="center"></vxe-table-column>
                                <vxe-table-column field="req_itemcode" title="项目代码" width="90"
                                    header-align="center"></vxe-table-column>
                                <template v-slot:fix>
                                    <div
                                        style="font-size: 17px; padding: 3px; background-color: #fff; text-align: center; font-weight: bold">
                                        <span style="color: blue; float: right; right: 0">金额：￥{{ detailAmountSum
                                        }}</span>
                                    </div>
                                </template>
                            </vxe-table>
                        </div>
                    </div>
                </rm-layout-top>
            </div>
        </div>

        <!-- 审核弹窗 -->
        <el-dialog width="500px" top="10px" :append-to-body="true" :close-on-click-modal="false" title="审  核"
            :visible.sync="approvalVisible" :destroy-on-close="true">
            <div>
                <table style="width: 100%">
                    <tr>
                        <td width="80" align="right" class="must-param">审核结果：</td>
                        <td>
                            <el-select placeholder="请选择" style="width: 100%;" v-model="approvalResult">
                                <el-option key="1" label="通过" value="1"></el-option>
                                <el-option key="2" label="退回" value="2"></el-option>
                            </el-select>
                        </td>
                    </tr>
                    <tr>
                        <td width="80" align="right" class="must-param" style="vertical-align: top">审核意见：</td>
                        <td>
                            <el-input type="textarea" v-model="auditmind" rows="5" ref="auditmind"></el-input>
                        </td>
                    </tr>
                </table>
                <div class="detail-operation">
                    <el-button class="el-button--310" @click="approvalFun()">确定</el-button>
                    <el-button class="el-button--310" @click="approvalVisible = false">取消</el-button>
                </div>
            </div>
        </el-dialog>

        <!-- 图片查看弹窗 -->
        <el-dialog width="500px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="查看照片"  :visible.sync="photoDialog" @close="clearPhoto()">
            <div style="width: 490px; height: 350px;">
                <div style="width: 100%; height: 98%;">
                    <el-carousel trigger="click" style="height: 100%; width: 100%;" height="100%" :autoplay="false">
                        <el-carousel-item v-for="(item,i) in LPicData" :key="i">
                            <div style="position:relative; height: 100%; width: 100%;">
                                <el-image :src="item" @click="onPreview(item)" style=" width: 100%; height: 99%;"></el-image>
                            </div>
                        </el-carousel-item>
                    </el-carousel>
                </div>
                <el-image-viewer v-if="showViewer" :on-close="closeViewer" :url-list="viewerList"/>
            </div>
        </el-dialog>
    </div>
</template>

<script type="text/javascript">
import reqitem from "@/components/common/reqitem";
import ElImageViewer from '../../../../element-ui/packages/image/src/image-viewer';
import XEUtils from "xe-utils";
export default {
    name: "LIS258",
    components: {
        ElImageViewer,
    },
    data() {
        return {
            searchObj: {
                txtpattype: "",
                txtcreateuser: "",
                txtpatname: "",
                txtpatidcard: "",
                txtpatno: "",
                txtreqitem: "",
                txthospcode: "",
                txtreqdeptno: "",
                txtreqstat: "",
                txtbarcode: "",
                txtdatetime1: this.$pub.InitDate(),
                txtdatetime2: this.$pub.InitDate(),
                isapproval: "0",
            },
            txtreqdeptname: "",
            txthospname: "",
            txtreqitemname: "",
            txtpattypename: "",
            txtcreateusername: "",
            ChkSaveThenPrintLabel: "1",
            ChkAutoAssignLabelQty: "0",
            ChkReqitemAutoemory: "0",
            ChkNoShowReqBarcode: "0",
            ChkNoShowPatnoThenCreateBarcode: "0",
            loading: false,
            nodata: true,
            right_loading: false,
            detail: [],
            master: [],
            masterList: {
                pat_agestr: "",
                pat_birth: "",
            },
            dblclickRow: [],
            dialogkey: 0,
            changeflag: false,
            dialogform: false,
            is_showselother: false,
            settingData: [],
            formheight: 0,
            formkey: 0,
            columnData: [],
            columnDataDisabled: [],
            columnDataChk: [],
            popdatatype: "",
            cx_backrpt_style: "",
            backbarmode: "2",
            cx_backrrintername: "",
            dialogtitle: "",
            field: "",
            datatype: "",
            kindno: "",
            initHosp: {
                hospcode: "",
                hospname: "",
                pat_hospcode: "",
                pat_hospname: "",
            },
            barcodestyle: "",
            cxbarcodeprinter: "",
            //DDL快速输入码
            InputCodeArr: [],
            forminfo: reqitem.forminfo,
            defaultCol: reqitem.defaultCol,
            allReqsheetTable: reqitem.allReqsheetTable,
            filterColumn: reqitem.filterColumn,
            showName: reqitem.showName,
            selplaceholder: reqitem.selplaceholder,
            fhaveUpt: false,
            haveUpt: false,
            dept: "",
            approvalVisible: false,
            reqsheetParam: {},
            IsAreaMode: false,
            allReqsheetList: [],
            fallReqsheetList: [],
            allReqsheetListMap: [],
            addreqitemname: "",
            testDialogX: 0,
            testDialogY: 0,
            tableReqsheetList: [],
            keyConfig: {
                isArrow: true,
                isEnter: true,
            },
            loginutype: this.$tool.getSession(this.$tool.loginutype),
            inputPattypeList: [],
            reqLocalseting: {
                reqinputloaclseting: 0,
                reqprintreceiptseting: 0,
                reqprintbarcodeseting: 1,
                reqreadidcardseting: 0,
            },
            applyentryneedapproval: "",
            copyCount: "",
            IsPrintCole: "0",
            isCopyMode: "0",
            approvalResult: "1",
            auditmind: "",
            photoDialog: false,
            showViewer: false,
            viewerList: [],
            LPicData: [],
        };
    },
    mounted() {
        this.initData(); //初始化下拉框的数据
        this.Queryddl();
    },
    computed: {
        datacnt() {
            if (!!this.master) {
                return this.master.length
            }
            else {
                return 0
            }
        },
        amountsum() {
            return XEUtils.sum(this.master, "amount");
        },
        detailAmountSum() {
            return XEUtils.sum(this.detail, "amount");
        },
        detailseq() {
            let data = this.$refs.rxTable.tableData;
            if (data.length > 0) {
                return (data.length + 1) * 10;
            } else {
                return 10;
            }
        },
    },
    methods: {
        btn_showselother() {
            this.is_showselother = !this.is_showselother;
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS258",
                    method: "post",
                    data: {
                        action: "showselother",
                        is_showselother: this.is_showselother ? "1" : "0",
                    },
                }).then((res) => { });
        },
        initData() {
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS258",
                    method: "post",
                    data: {
                        action: "initdata",
                    },
                })
                .then((res) => {
                    this.settingData = res.columnData;
                    this.initHosp.hospcode = res.hospcode;
                    this.initHosp.hospname = res.hospname;
                    this.initHosp.pat_hospcode = res.hospcode;
                    this.initHosp.pat_hospname = res.hospname;
                    this.barcodestyle = res.barcodestyle;
                    this.cxbarcodeprinter = res.cxbarcodeprinter;
                    this.reqLocalseting.reqinputloaclseting = res.reqinputloaclseting;
                    this.reqLocalseting.reqprintreceiptseting = res.reqprintreceiptseting;
                    this.reqLocalseting.reqprintbarcodeseting = res.reqprintbarcodeseting;
                    this.reqLocalseting.reqreadidcardseting = res.reqreadidcardseting;
                    this.is_showselother = res.showselother == "0" ? false : true;
                    this.InitColumn();
                    this.dept = res.dept;
                    this.fhaveUpt = res.haveUpt;
                    this.haveUpt = this.fhaveUpt;
                    this.IsAreaMode = res.IsAreaMode;
                    this.cx_backrpt_style = res.cx_backrpt_style;
                    this.backbarmode = res.backbarmode;
                    this.cx_backrrintername = res.cx_backrrintername;
                    this.allReqsheetList = res.Reqitem2;
                    this.allReqsheetListMap = this.$pub.arrayToMap(this.allReqsheetList, "req_itemcode", "req_itemname");
                    this.applyentryneedapproval = res.applyentryneedapproval;
                })
                .catch((err) => { });
        },
        // 在 Input 值改变时触发
        handleEdit(e) {
            let value = e.replace(/^(0+)|[^\d]+/g, ''); // 以0开头或者输入非数字，会被替换成空
            value = value.replace(/(\d{3})\d*/, '$1') // 最多保留3位整数
            this.copyCount = value
        },
        Queryddl() {
            const loading = this.$loading({
                lock: true,
                text: "Loading",
                spinner: "el-icon-loading",
                background: "rgba(0, 0, 0, 0.7)",
            });
            //初始化获取所有的InputCodeArr
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS258",
                    method: "post",
                    data: {
                        action: "queryddl",
                    },
                })
                .then((res) => {
                    var inputCodeArr = res.inputCodeArr;
                    var sale = inputCodeArr.find((item) => item.key == "sampled_user$sampled_username");
                    if (sale) {
                        inputCodeArr.push({ key: "saleman$saleman", list: sale.list });
                    }
                    this.InputCodeArr = inputCodeArr;
                    let pattype = inputCodeArr.find((item) => item.key == "pat_typecode$pat_typename");
                    if (pattype) this.inputPattypeList = pattype.list;
                    loading.close();
                });
        },
        InitColumn() {
            //取出所有可见可編輯的数据
            let data = this.settingData.filter((item) => item.visibled == "1" && item.enabled == "1");
            //取出所有可见不可編輯的数据
            let disdata = this.settingData.filter((item) => item.visibled == "1" && item.enabled != "1");
            this.defaultCol.forEach((item) => {
                let tempdata = { col_code: item.code, col_label: item.name, col_name: item.name, default_val: "", enabled: "0", noedit: "", prg_no: "LIS258", rem_last: "0", reserved: "", seq_no: 10, valuelist: "", valuetype: item.type, visibled: "1" };
                disdata.push(tempdata);
            });
            //取出可见所有checkbox的数据
            let chkdata = [];
            let chkdata1 = data.filter((item) => item.valuetype == "1");
            data = data.filter((item) => item.valuetype != "1");
            let chkdata2 = disdata.filter((item) => item.valuetype == "1");
            disdata = disdata.filter((item) => item.valuetype != "1");
            chkdata = XEUtils.union(chkdata1, chkdata2);
            //计算行数
            let len = data.length;
            let rows = Math.ceil(len / 3);
            data.forEach((item, index) => {
                item.seqflag = index + 1;
            });
            //计算高度
            // this.formheight = 23 * (rows + Math.ceil(disdata.length / 3) + Math.ceil(chkdata.length / 3));
            this.formheight = 23 * (rows + Math.ceil(chkdata.length / 3));
            this.formkey++;
            //焦点定位赋值
            let ys = len % 3;
            let column1 = 1;
            let column2 = rows + 1;
            let column3 = len % 3 == 1 ? rows * 2 : rows * 2 + 1;
            let columnarr = [column1, column2, column3];
            let disarraycol = XEUtils.chunk(disdata, 3);
            this.columnDataDisabled = disarraycol;
            //带有checkbox在目前只有两个，暂时先这样
            let chkarraycol = XEUtils.chunk(chkdata, 3);
            this.columnDataChk = chkarraycol;

            let arraycol = XEUtils.chunk(data, 3);
            this.columnData = arraycol;
            for (let i = 0; i < arraycol.length; i++) {
                for (let j = 0; j < arraycol[i].length; j++) {
                    arraycol[i][j].seqflag = columnarr[j];
                    columnarr[j]++;
                }
            }
        },
        currentChangeEvent({ row }) {
            if (!this.changeflag) {
                this.getApplicationdetails(row);
            } else {
                this.$refs.lxTableTemp.setCurrentRow(this.selectRow);
            }
        },
        async getApplicationdetails(row) {
            try {
                if (!!row) {
                    this.selectRow = row;
                    const res = await this.$tool.request({
                        url: "LIS/LIS2/LIS258",
                        method: "post",
                        data: {
                            action: "getApplicationdetails",
                            id: row.id,
                        },
                    });
                    this.masterList = res.application[0];
                    this.oldmasterList = XEUtils.clone(res.application[0], true);
                    this.detail = res.detail;
                    if (res.detail.length > 0) {
                        this.$refs.rxTable.setCurrentRow(res.detail[0]);
                    } else {
                        this.$refs.rxTable.setCurrentRow(null);
                    }
                } else {
                    this.HighLightRow(false);
                }
            } catch (e) {
                this.$alert(e);
            }
        },
        queryData() {
            this.loading = true;
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS258",
                    method: "post",
                    data: {
                        action: "queryData",
                        ...this.searchObj,
                    },
                })
                .then((res) => {
                    this.master = [];
                    this.master = res.data;
                    this.loading = false;
                })
                .catch((err) => {
                    this.$alert(err, "提示");
                    this.loading = false;
                });
        },
        HighLightRow(row) {
            if (!!row) {
                this.$refs.lxTableTemp.setCurrentRow(row);
                this.getApplicationdetails(row);
            } else {
                this.$refs.lxTableTemp.setCurrentRow(null);
                this.masterList = {
                    hospcode: XEUtils.clone(this.initHosp.hospcode, true),
                    hospname: XEUtils.clone(this.initHosp.hospname, true),
                    pat_hospcode: XEUtils.clone(this.initHosp.pat_hospcode, true),
                    pat_hospname: XEUtils.clone(this.initHosp.pat_hospname, true),
                };
                this.detail = [];
            }
        },
        //审核
        btnApprove() {
            try {
                var data = this.$refs.lxTableTemp.getSelectRecords();
                console.log(data);
                if (data.length > 0) {
                    this.$confirm("本次选中 <span style='color:red;'>" + data.length + "</span> 条数据，确定审核勾选的申请吗？", "提示", {
                        dangerouslyUseHTMLString: true,
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning",
                    })
                        .then(() => {
                            this.ApproveIDs = '';
                            for (var i = 0; i < data.length; i++) {
                                this.ApproveIDs += data[i].id + ',';
                            }
                            if (!!this.ApproveIDs) {
                                this.ApproveIDs = this.ApproveIDs.substring(0, this.ApproveIDs.length - 1);
                            }
                            this.approvalVisible = true;
                        })
                        .catch(() => { });
                } else {
                    var approw = this.$refs.lxTableTemp.getCurrentRow();
                    if (approw) {
                        var msg = "确定审核病人姓名为：<span style='color:red;'>" + approw.pat_name + "</span> 的申请吗？";
                        this.$confirm(msg, "提示", {
                            dangerouslyUseHTMLString: true,
                            confirmButtonText: "确定",
                            cancelButtonText: "取消",
                            type: "warning",
                        })
                            .then(() => {
                                this.ApproveIDs = approw.id;
                                this.approvalVisible = true;
                            })
                            .catch(() => { });
                    }
                }
            } catch (e) {
                console.log("error", e);
            }
        },
        approvalFun() {
            if (!this.auditmind) {
                this.$alert("请输入审核意见！", "提示");
                return false;
            }

            this.$tool
                .request({
                    url: "LIS/LIS2/LIS258",
                    method: "post",
                    data: {
                        action: "approvalApplication",
                        ids: this.ApproveIDs,
                        approvalresult: this.approvalResult,
                        auditmind: this.auditmind,
                    },
                })
                .then((res) => {
                    if (res.flag == "1") {
                        this.$pub.message(this, "保存成功", "success");
                        this.queryData();
                    } else {
                        this.$alert("保存主数据失败" + res.msg, "错误");
                    }
                    this.approvalVisible = false;
                })
                .catch((err) => {
                    console.log("error", err);
                });
        },
        dblclickTemp({ row, column }) {
            //temp表双击事件
            if(column.property == 'isPhoto'){
                //弹窗预览图片
                this.getImage(row);
            }
        },
        async getImage(row) {
            this.LPicData = [];
            if(row.isPhoto != '0'){
                //获取图片
                const r = await this.$tool.request({
                    url: "LIS/LIS2/LIS258",
                    method: "post",
                    data: {
                        action: "getimage",
                        barcode: row.id,
                    },
                });
                if (r.images.length > 0) {
                    r.images.forEach(element => {
                        this.LPicData.push(element.Item1);
                    });
                    //打开弹窗展示图片
                    this.photoDialog = true;
                }
            }
        },
        onPreview(imgList) {
            this.viewerList = [imgList];
            this.showViewer = true
        },
        closeViewer() {
            this.viewerList = [];
            this.showViewer = false
        },
        clearPhoto(){
            this.LPicData = [];
        },
        // 回车切换输入框
        nextFocus(colcode, index) {
        },
        InputFocus(colcode, index) {
            let that = this;
            that.HightlightPos(that.$refs["input" + index][0].value, colcode, index);
        },
        InputMove(moveDirection, colcode, index) {
            if (moveDirection == "up") {
                if (index == 1) return false;
                var that = this;
                var focusIndex = index - 1;
                setTimeout(function () {
                    that.$refs["input" + focusIndex][0].focus();
                    if (["_dt", "_date", "pat_birth"].indexOf(that.$refs["input" + focusIndex][0].id) == -1) {
                    } else {
                        that.$refs["input" + focusIndex][0].select();
                    }
                }, 1);
            } else {
                this.nextFocus(colcode, index);
            }
        },
        hasChange() {
            this.changeflag = true;
        },
        opendialog(col) {
            if (col.noedit == "1") return false;
            this.dialogkey++;
            console.log(this.forminfo);
            let info = this.forminfo[col.col_code];
            if (!info) return false;
            let action = info.action.split("$");
            // let field = info.field.split("$");
            this.dialogtitle = info.title;
            this.datatype = action[0];
            this.kindno = action[1];
            this.field = info.field + "$" + "input" + col.seqflag;
            this.dialogform = true;
        },
        async inputChangeEvent(value, colinfo, refinfo) {
        },
        SpaceEvent(col) {
            var val = this.masterList[this.forminfo[col.col_code].field.split("$")[1]];
            if (!val.replace(/\s*/g, "")) {
                this.opendialog(col);
            }
        },
        RowClassName({ row }) {
            return this.$pub.getreqstatclass(row.req_stat);
        },
        HightlightPos(myValue, colcode, index) {
            if (!myValue) myValue = "";
            try {
                var myField = {};
                if (colcode.toUpperCase().indexOf("_DT") == -1 || colcode.toUpperCase().indexOf("_DATE") == -1 || colcode == "pat_birth") {
                    myField = this.$refs["input" + index][0].$refs.reference.$refs.input;
                } else {
                    myField = this.$refs["input" + index][0].$refs.input;
                }
                if (myField.selectionStart || myField.selectionStart === 0) {
                    var startPos = myField.selectionStart;
                    var endPos = myField.selectionEnd;
                    this.$nextTick(() => {
                        myField.selectionStart = 0;
                        myField.selectionEnd = startPos + myValue.length;
                    }); // 这句是重点, 圈起来
                    myField.focus();
                    myField.setSelectionRange(myField, myField.selectionStart, myField.selectionEnd);
                }
            } catch (e) { }
        },
        deptChange(code, name) {
            this.searchObj.txtreqdeptno = code;
            this.txtreqdeptname = name;
        },
        hospitalChange(code, name) {
            this.searchObj.txthospcode = code;
            this.txthospname = name;
        },
        reqitemChange(code, name) {
            this.searchObj.txtreqitem = code;
            this.txtreqitemname = name;
        },
        PTChange(code, name) {
            this.searchObj.txtpattype = code;
            this.txtpattypename = name;
        },
        userinfoChange(code, name) {
            this.searchObj.txtcreateuser = code;
            this.txtcreateusername = name;
        },
        closeReqitem(type, ref) {
            if (type == 1) {
                // 组件
                this.$refs[ref].$refs.xTable.clearSelection();
            } else {
                this.$refs[ref].clearSelection();
            }
        },
        getShowName(code, list, row) {
            if (row) {
                row.req_itemname = this[list + "Map"].get(code);
            }
            return this[list + "Map"].get(code);
        },
        activeMethod({ row, column }) {
        },
        selectCurrChange({ row }) {
            this.selectReqChange(row);
        },
        selectTableRow(row) {
            if (!row) return false;
            this.$nextTick(() => {
                this.selectRow = row;
                this.$refs.selectTable.setCurrentRow(row);
                this.selectReqChange(row);
            });
        },
        selectReqChange(row) {
            if (row) {
                this.$refs.reqImport.slectReqItem(row);
            } else {
                this.addreqitemname = "";
            }
        },
        exportExcel() {
            let tableColumn = this.$refs.lxTableTemp.getColumns();
            let extableColumn = [];
            tableColumn.forEach((item) => {
                extableColumn.push({ title: item.title, field: item.property });
            });
            let filtertxt = this.getExportFilter();
            this.$pub.exportTableExcel(this.master, extableColumn, "LIS258 申请审核.xlsx", filtertxt);
        },
        // 获取当前导出文件的所有查询条件
        getExportFilter() {
            let filtertxt = "创建日期:" + XEUtils.toDateString(this.searchObj.txtdatetime1, "yyyy-MM-dd") + "至" + XEUtils.toDateString(this.searchObj.txtdatetime2, "yyyy-MM-dd") + "; ";
            if(this.searchObj.txtbarcode) filtertxt += "条码号:" + this.searchObj.txtbarcode + "; ";
            if(this.searchObj.txtreqdeptno) filtertxt += "申请科室:" + this.txtreqdeptname + "; ";
            if(this.searchObj.txthospcode) filtertxt += "送检医院:" + this.txthospname + "; ";
            if(this.searchObj.txtreqitem) filtertxt += "申请项目:" + this.txtreqitemname + "; ";
            if(this.searchObj.txtpatno) filtertxt += "病历号:" + this.searchObj.txtpatno + "; ";
            if(this.searchObj.txtpatname) filtertxt += "病人姓名:" + this.searchObj.txtpatname + "; ";
            if(this.searchObj.txtpatidcard) filtertxt += "身份证号:" + this.searchObj.txtpatidcard + "; ";
            if(this.searchObj.txtpattype) filtertxt += "病人类型:" + this.txtpattypename + "; ";
            if(this.searchObj.txtcreateuser) filtertxt += "创建用户:" + this.txtcreateusername + "; ";
            return filtertxt;
        },
    },
    beforeRouteEnter(to, from, next) {
        next((vm) => {
            // 通过 `vm` 访问组件实例
            let that = vm;
            let arr = []; //组合按键 暂时支持alt吧 将来可以扩展
            document.onkeydown = function (e) {
                let key = window.event.keyCode;
                //console.log("key=", key);
                if (arr.length > 0) {
                    //65到90 a到z（A到Z）
                    if (key == 67) {
                        //alert("复位");
                        //that.btnreset_click();
                    } else if (key == 66) {
                        // alert("单打条码");
                    } else if (key == 76) {
                        //alert("重打回单");
                    }
                } else {
                    //112到135 F1到F24
                    if (key == 117) {
                        if (that.changeflag) {
                            that.btnApprove();
                        }
                    }
                }
            };
            document.onkeyup = function (e) {
                let key = window.event.keyCode;
                if (key == 18) {
                    arr = [];
                }
            };
        });
    },
};
</script>

<style scoped>
.pagetop {
    width: 100%;
    height: 70px;
    display: -webkit-box;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    border: 1px solid #ccc;
    position: absolute;
    z-index: 99;
    overflow-x: auto;
    white-space: nowrap;
}

::-webkit-scrollbar {
    width: 0px;
    height: 5px;
    border: 4px solid white;
}

::-webkit-scrollbar-thumb {
    background-color: #c1c1c1;
}

::-webkit-scrollbar-track {
    background-color: #f1f1f1;
}

/* Buttons */
::-webkit-scrollbar-button:single-button {
    background-color: #bbbbbb;
    display: block;
    border-style: solid;
    height: 5px;
    width: 5px;
}

/* Left */
::-webkit-scrollbar-button:horizontal:decrement {
    margin-right: 2px;
    border-width: 4px 4px 4px 0;
    border-color: #f1f1f1 transparent #f1f1f1 #f1f1f1;
    background-color: #000000;
}

::-webkit-scrollbar-button:horizontal:decrement:hover {
    border-color: #d2d2d2 transparent #d2d2d2 #d2d2d2;
}

/* Right */
::-webkit-scrollbar-button:horizontal:increment {
    margin-left: 2px;
    border-width: 4px 0 4px 4px;
    border-color: #f1f1f1 #f1f1f1 #f1f1f1 transparent;
    background-color: #000000;
}

::-webkit-scrollbar-button:horizontal:increment:hover {
    border-color: #d2d2d2 #d2d2d2 #d2d2d2 transparent;
}

.pagecenter {
    position: absolute;
    top: 75px;
    width: 100%;
    left: 0;
    bottom: 0px;
    overflow: auto;
}

.pagetopother {
    width: 100%;
    height: 100px;
    display: -webkit-box;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    border: 1px solid #ccc;
    position: absolute;
    z-index: 99;
}

.pagecenterother {
    position: absolute;
    top: 105px;
    width: 100%;
    left: 0;
    bottom: 0px;
    overflow: auto;
}

.middle-center {
    position: absolute;
    height: 100%;
    left: 0px;
    right: 585px;
    overflow: auto;
}

.middle-right {
    position: absolute;
    height: 100%;
    width: 580px;
    right: 0px;
}

.table1style tr td {
    padding: 1px 2px 1px 2px;
}

.table2style tr td {
    padding: 0px 5px 0px 3px;
}

.el-checkbox__label {
    display: inline-block;
    padding-left: 2px;
    line-height: 19px;
    font-size: 14px;
}

/deep/.myclass>.table2style .el-input.is-disabled .el-input__inner {
    border-color: #e4e7ed;
    color: #c0c4cc;
    cursor: not-allowed;
}

/deep/ .myclass .el-input--suffix .el-input__inner {
    padding-right: 10px;
}

/deep/.myclass>.table2style .el-input--small .el-input__inner {
    height: 20px !important;
    line-height: 20px !important;
}

/deep/ .myclass>.table2style .el-input--small .el-input__icon {
    line-height: 18px !important;
}

/deep/ .el-input--prefix .el-input__inner {
    padding-left: 25px;
}

/deep/ .el-button.is-disabled {
    border: 0px;
    color: grey;
    background-color: #e6e6e6;
    font-weight: normal;
}

/deep/ .req-popcontent .el-tabs__content {
    position: relative !important;
    top: 0px !important;
}

.show-area {
    position: absolute;
    height: 100%;
    width: 100%;
    z-index: 1999;
    background: rgba(204, 204, 204, 0.2);
}

/deep/ .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after {
    border-color: #000000;
}

.detail-operation {
    margin: 5px 0;
    text-align: right;
}

/* .req-select .hover {
    background-color: #d9dce0 !important;
}
.req-select .el-select-dropdown__item {
    font-size: 12px;
}
.req-el-option {
    display: inline-block;
} */
.req-select {
    display: inline-block;
    width: 180px;
    margin-right: 10px;
}

/deep/ .req-select .el-select {
    width: 100%;
}

/deep/ .table-bottom-content .vxe-table--empty-block {
    height: calc(100% - 32px);
}

.reqitem-dialog {
    position: absolute;
    z-index: 10000;
}

.reqitem-select {
    height: 250px;
}

/deep/ .reqitem-select .vxe-table {
    border: 0 !important;
}

/deep/ .reqitem-select .vxe-table .vxe-cell {
    padding: 0 5px;
}

/deep/ .vxe-table--tooltip-wrapper.theme--dark {
    z-index: 10001 !important;
}

/* /deep/ .reqitem-select .el-table{
    height: 100%;
    overflow-y: auto;
}
/deep/ .reqitem-select .el-table th {
    line-height: 23px !important;
}
/deep/ .reqitem-select .vxe-table .cell {
    padding: 0 5px;
} */
/deep/ .pagetop .el-input--suffix .el-input__inner {
    padding-right: 10px !important;
}

/deep/ .pagetopother .el-input--suffix .el-input__inner {
    padding-right: 10px !important;
}
</style>